load("@prelude//toolchains/android/tools:build_rules.bzl", "buck_java_binary", "buck_java_library")
load("@prelude//utils:source_listing.bzl", "source_listing")

oncall("android_devxx")

source_listing()

EXO_RESOURCES_REWRITER_SRCS = ["ExoResourcesRewriterExecutableMain.java"]

MERGE_ANDROID_RESOURCES_SRCS = [
    "MergeAndroidResources.java",
    "MergeAndroidResourcesExecutableMain.java",
]

MERGE_ASSETS_SRCS = [
    "MergeAssetsUtils.java",
    "MergeAssetsExecutableMain.java",
]

buck_java_library(
    name = "resources",
    srcs = glob(
        ["*.java"],
        exclude = EXO_RESOURCES_REWRITER_SRCS + MERGE_ANDROID_RESOURCES_SRCS + MERGE_ASSETS_SRCS,
    ),
    visibility = ["PUBLIC"],
    deps = [
        "prelude//toolchains/android/src/com/facebook/buck/io/file:file",
        "prelude//toolchains/android/src/com/facebook/buck/io/filesystem/impl:utils",
        "prelude//toolchains/android/src/com/facebook/buck/util:util",
        "prelude//toolchains/android/src/com/facebook/buck/util/zip:zip",
        "prelude//toolchains/android/third-party:guava",
        "prelude//toolchains/android/third-party:jsr305",
    ],
)

buck_java_library(
    name = "merge_android_resources",
    srcs = MERGE_ANDROID_RESOURCES_SRCS,
    visibility = ["PUBLIC"],
    deps = [
        "prelude//toolchains/android/src/com/facebook/buck/android/aapt:r_dot_txt",
        "prelude//toolchains/android/src/com/facebook/buck/core/filesystems:filesystems",
        "prelude//toolchains/android/src/com/facebook/buck/core/util/log:log",
        "prelude//toolchains/android/src/com/facebook/buck/util:throwing_print_writer",
        "prelude//toolchains/android/src/com/facebook/buck/util/json:json",
        "prelude//toolchains/android/src/com/facebook/buck/util/zip:zip",
        "prelude//toolchains/android/third-party:args4j",
        "prelude//toolchains/android/third-party:guava",
    ],
)

buck_java_binary(
    name = "merge_android_resources_binary",
    main_class = "com.facebook.buck.android.resources.MergeAndroidResourcesExecutableMain",
    visibility = [
        "PUBLIC",
    ],
    deps = [
        ":merge_android_resources",
    ],
)

buck_java_library(
    name = "merge_assets",
    srcs = MERGE_ASSETS_SRCS,
    java_version = "11",
    visibility = ["PUBLIC"],
    deps = [
        "prelude//toolchains/android/src/com/facebook/buck/android/apkmodule:apkmodule",
        "prelude//toolchains/android/src/com/facebook/buck/io/filesystem/impl:utils",
        "prelude//toolchains/android/src/com/facebook/buck/util/json:json",
        "prelude//toolchains/android/third-party:args4j",
        "prelude//toolchains/android/third-party:guava",
        ":resources",
    ],
)

buck_java_binary(
    name = "merge_assets_binary",
    main_class = "com.facebook.buck.android.resources.MergeAssetsExecutableMain",
    visibility = [
        "PUBLIC",
    ],
    deps = [
        ":merge_assets",
    ],
)

buck_java_library(
    name = "exo_resources_rewriter",
    srcs = EXO_RESOURCES_REWRITER_SRCS,
    java_version = "11",
    visibility = ["PUBLIC"],
    deps = [
        "prelude//toolchains/android/src/com/facebook/buck/android/zipalign:zipalign",
        "prelude//toolchains/android/src/com/facebook/buck/core/filesystems:filesystems",
        "prelude//toolchains/android/third-party:args4j",
        "prelude//toolchains/android/third-party:guava",
        ":resources",
    ],
)

buck_java_binary(
    name = "exo_resources_rewriter_binary",
    main_class = "com.facebook.buck.android.resources.ExoResourcesRewriterExecutableMain",
    visibility = [
        "PUBLIC",
    ],
    deps = [
        ":exo_resources_rewriter",
    ],
)
